home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The X-Philes (2nd Revision)
/
The X-Philes Number 1 (1995).iso
/
xphiles
/
hp95
/
gnuchess.arc
/
cvt.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-16
|
2KB
|
105 lines
# include <stdio.h>
# define SET_BIT(b) bits[i >> 3] |= (1 << (7 - (b & 7)))
int line_no = 0;
char lbuf[BUFSIZ];
char bits[1024];
FILE *fp = stdin;
int height;
int max_size;
main(argc, argv)
int argc;
char **argv;
{
/***********************************************/
/* Read the header to tell us how big the */
/* bitmaps should be. */
/***********************************************/
while (!feof(fp)) {
if (fgets(lbuf, sizeof lbuf - 1, fp) == NULL)
break;
line_no++;
if (*lbuf == '#' || *lbuf == '\n')
continue;
if (*lbuf == '=')
break;
if (strncmp(lbuf, "height=", 7) == 0) {
height = atoi(lbuf + 7);
continue;
}
}
if (height == 0) {
fprintf(stderr, "height not defined in bitmap file\n");
exit(1);
}
while (!feof(fp))
read_glyph();
printf("/* max buffer size=%d bytes */\n", max_size);
}
read_glyph()
{
char *cp;
int i;
int r = 0;
int c = 0;
int w = 0;
memset(bits, 0, sizeof bits);
while (*lbuf != '=') {
if (fgets(lbuf, sizeof lbuf - 1, fp) == NULL)
return;
line_no++;
}
for (cp = lbuf; *cp == '='; )
cp++;
printf("\t/*");
while (*cp != '=')
printf("%c", *cp++);
printf("*/\n");
while (1) {
if (fgets(lbuf, sizeof lbuf - 1, fp) == NULL)
break;
line_no++;
if (*lbuf == '=' || *lbuf == '\n')
break;
cp = lbuf;
if (*cp++ != '\t') {
fprintf(stderr, "Line %d: missing tab character\n", line_no);
exit(1);
}
if (*cp == '|')
cp++;
for (c = 0; *cp != '\n' && *cp != '|'; c++) {
if (*cp++ != ' ') {
i = r * ((w + 7) & ~7) + c;
SET_BIT(i);
}
}
if (c > w)
w = c;
r++;
}
if (r == 0)
return;
if (r != height) {
fprintf(stderr, "Line %d: Glyph has %d rows out of %d\n", r, height);
}
printf("\t{1, 1, %d, %d,\n\t", w, height);
w = (w + 7) & ~7;
if (height * w / 8 > max_size)
max_size = height * w / 8;
for (i = 0; i < height * w / 8; i++) {
if (i)
printf(", ");
if ((i & 7) == 7)
printf("\n\t");
printf("0x%02x", bits[i] & 0xff);
}
printf("},\n");
}